package rxt.huiyi.com.rxterfit;

import android.app.Application;
import android.content.Context;

import rxt.huiyi.com.rxterfit.Logger.LogLevel;
import rxt.huiyi.com.rxterfit.Logger.Logger;
import rxt.huiyi.com.rxterfit.component.AppComponent;
import rxt.huiyi.com.rxterfit.component.DaggerAppComponent;
import rxt.huiyi.com.rxterfit.constant.Constants;
import rxt.huiyi.com.rxterfit.module.JobExecutor;
import rxt.huiyi.com.rxterfit.module.RxJavaExecuter;
import rxt.huiyi.com.rxterfit.module.UIThread;
import rxt.huiyi.com.rxterfit.module.app.AppModule;
import rxt.huiyi.com.rxterfit.module.app.GsonModule;
import rxt.huiyi.com.rxterfit.retrofitService.ReterfitService;

/**
 * Created by huiyi on 2017/4/14.
 */
public class RxJavaApplication extends Application {

    public static AppComponent appComponent;

    @Override
    public void onCreate() {
        super.onCreate();
        setLogPrinter();

        appComponent = DaggerAppComponent.builder()
                .appModule(new AppModule(this))
                .reterfitService(new ReterfitService())
                .rxJavaExecuter(new RxJavaExecuter(JobExecutor.instance(), UIThread.instance()))
                .gsonModule(new GsonModule())
                .build();
    }

    public static RxJavaApplication get(Context context) {
        return (RxJavaApplication) context.getApplicationContext();
    }

    public static AppComponent getRxAppComponent() {
        return appComponent;
    }

    private void setLogPrinter() {
        if (BuildFlag.DEBGU) {
            Logger.init(Constants.TAG).logLevel(LogLevel.FULL);
        } else
            Logger.init(Constants.TAG).logLevel(LogLevel.NONE);
    }

}
